import React, { useState } from 'react';
import { history, connect } from 'umi';
import { Card, Button, Form } from 'antd';
import { Col, Row, Tag, Tooltip, Space, notification } from 'antd';
import DrawerCondition from '@/components/DrawerCondition';
import FormCondition from '@/components/FormCondition';
import SelectModel from './../SelectModel';
import { TeamOutlined, QuestionCircleOutlined } from '@ant-design/icons';
import Uploadjs from '@/utils/aliOssUpload';
import { useEffect } from 'react';
const sendExpress = (props) => {
  const { dispatch, visible = {}, onClose, handleCallback, loading, searchLoading } = props;
  const [modelVisible, setModelVisible] = useState(false);
  const [data, setData] = useState(null);
  const { show = false, detail = {} } = visible;
  const [list, setList] = useState({});
  const { id } = detail
  const [form] = Form.useForm();
  // 新增修改 传id修改 不传id新增
  const fetchRoleEdit = () => {
    form.validateFields().then(async (values) => {
      dispatch({
        type: 'expressTemplate/fakeSendExpress',
        payload: {
          ...values,
          id,
        },
        callback: () => {
          onClose();
          handleCallback();
        },
      });
    });
  };
  useEffect(() => {
    dispatch({
      type: 'expressTemplate/fetchListExpressCompany',
      callback: (e) => {
        setList(e)
      }
    })
  }, [])
  const modalProps = {
    title: `设置发货`,
    visible: show,
    onClose,
    destroyOnClose: true,
    footer: (
      <Button type="primary" loading={loading} onClick={fetchRoleEdit}>
        确定
      </Button>
    ),
  };



  const formItems = [
    {
      label: '快递公司',
      name: 'expressCompanyCode',
      type: 'select',
      select: list,
      onChange: (e, { option }) => {
        form.setFieldsValue({
          expressCompany: option.companyName
        })
      },
      fieldNames: { label: 'companyName', value: 'companyCode' },
    },
    {
      label: '快递公司代码',
      name: 'expressCompany',
      hidden: true
    },


    {
      label: '快递单号',
      name: 'expressNo',
    },

  ];

  return (
    <>
      <DrawerCondition {...modalProps}>
        <FormCondition form={form} formItems={formItems} initialValues={detail}></FormCondition>
      </DrawerCondition>
      <SelectModel
        onClose={() => {
          setModelVisible(false);
        }}
        onOk={(e) => setData(e)}
        visible={modelVisible}
      ></SelectModel>
    </>
  );
};
export default connect(({ system, loading }) => ({
  loading: loading.models.system,
  searchLoading: loading.effects['system/fetchChatCodePage'],
}))(sendExpress);
